#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

const int N = 2e5 + 10;

int dp[N], backup[N], q[N];
int n, m;
int v, w, s;

int main()
{
    scanf("%d%d", &n, &m);
    for (int i = 0; i < n; i ++ )
    {
        scanf("%d%d%d", &v, &w, &s);
        memcpy(backup, dp, sizeof(dp));
        for (int j = 0; j < v; j ++ )
        {
            int hh = 0, tt = -1;
            for (int k = j; k <= m; k += v)
            {
                if (hh <= tt && k - s * v > q[hh]) hh ++ ;
                
                while (hh <= tt && backup[q[tt]] - (q[tt] - j)/v * w <= backup[k] - (k - j)/v * w) tt--;
                
                if (hh <= tt)
                    dp[k] = max(dp[k], backup[q[hh]] + (k - q[hh])/ v * w);
                    
                q[++ tt] = k;
            }
        }
        
    }
    
    cout << dp[m];
    
    return 0;
}
